package com.bank.doman.auth.server.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.crypto.SecureUtil;
import com.bank.common.exception.ParamException;
import com.bank.common.io.PageVo;
import com.bank.doman.auth.dao.UserDao;
import com.bank.doman.auth.dao.model.User;
import com.bank.doman.auth.io.vo.UserVo;
import com.bank.doman.auth.server.UserServiceI;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserServiceI {

    @Resource
    private UserDao userDao;

    @Override
    public PageVo<UserVo> getUserList() {
        List<User> userList = userDao.selectAll();
        return null;
    }

    @Override
    public UserVo login(String acount, String password) {
        User quer = new User();
        quer.setAccount(acount);
        User user = userDao.selectOne(quer);
        System.out.println(SecureUtil.md5(password));
        if(user==null||!user.getPassword().equals(SecureUtil.md5(password))){
            throw new ParamException("账号或者密码不正确");
        }
        return BeanUtil.toBean(user,UserVo.class);
    }

    @Override
    public UserVo userInfo(Long id) {
        return BeanUtil.toBean(userDao.selectByPrimaryKey(id),UserVo.class);
    }
}
